package com.example.myapplication.ui.adapter

import android.text.TextUtils
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.myapplication.R
import com.example.myapplication.bean.article.ArticleBean

/**
 *首页列表的adapter
 *
 * @author : Kun
 * @date : 2021/6/2
 * @time : 14:42
 */
class ArticleAdapter(layoutResId: Int, mList: ArrayList<ArticleBean>?) :
    BaseQuickAdapter<ArticleBean, BaseViewHolder>(layoutResId, mList), LoadMoreModule {
    /**
     * 类型 0 默认， 1 我的收藏
     */
    var type = 0

    override fun convert(holder: BaseViewHolder, item: ArticleBean) {
        holder.setText(R.id.tv_title, item.title)
        if (TextUtils.isEmpty(item.niceDate)) {
            holder.setGone(R.id.tv_time, true)
        } else {
            holder.setVisible(R.id.tv_time, true)
            holder.setText(R.id.tv_time, "时间：" + item.niceDate)
        }
        if (TextUtils.isEmpty(item.author)) {
            if (TextUtils.isEmpty(item.shareUser)) {
                holder.setGone(R.id.tv_author, true)
            } else {
                holder.setVisible(R.id.tv_author, true)
                holder.setText(R.id.tv_author, "分享人：" + item.shareUser)
            }
        } else {
            holder.setVisible(R.id.tv_author, true)
            holder.setText(R.id.tv_author, "作者：" + item.author)
        }
        holder.setGone(R.id.tv_top, !item.isTop)
        holder.setGone(R.id.tv_new, !item.fresh)

        holder.getView<View>(R.id.view_collect).isSelected = item.collect
        holder.setVisible(R.id.view_collect, type != 1)
    }
}